class BlogPostsController < ApplicationController

  def index
     @blog_posts = BlogPost.search(params[:search])
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @blog_posts }
    end
  end
  def search
    @blog_posts = BlogPost.search params[:q]
    render :action => "index"
  end
 

 def show
     @blog_post = BlogPost.find(params[:id])
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @blog_posts }
    end
   end
 

 def new
     @blog_post = BlogPost.new
     respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @blog_posts }
    end
   end
 

 def create
     @blog_post = BlogPost.new(params[:blog_post]) 
    respond_to do |format|
      if @blog_post.save
        format.html { redirect_to @blog_post, notice: 'Article was successfully created.' }
        format.json { render json: @blog_post, status: :created, location: @blog_post }
      else
        format.html { render action: "new" }
        format.json { render json: @blog_post.errors, status: :unprocessable_entity }
      end
    end

   end
 

 def destroy
     @blog_post = BlogPost.find(params[:id])
     @blog_post.destroy

    respond_to do |format|
      format.html { redirect_to blog_posts_url }
      format.json { head :no_content }
    end
   end

end
